package com.bank.util;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

public class SessionUtils {

	protected static final Logger logger = Logger.getLogger(SessionUtils.class);

	private static final String SESSION_USER_NAME = "session_user_name";
	private static final String SESSION_USER_NUMBER = "session_user_number";//柜员代号
	private static final String SESSION_USER_ORI   = "session_user_ori";//交易机构
	private static final String SESSION_USER_ID = "session_user_id";
	private static final String SESSION_WORK_DATE  = "session_work_date";
	private static final String SESSIO_ID = "session_id";

	/**
	 * 设置session的值
	 * 
	 * @param request
	 * @param key
	 * @param value
	 */
	public static void setAttr(HttpServletRequest request, String key, Object value) {
		request.getSession(true).setAttribute(key, value);
	}

	/**
	 * 获取session的值
	 * 
	 * @param request
	 * @param key
	 * @param value
	 */
	public static Object getAttr(HttpServletRequest request, String key) {
		return request.getSession(true).getAttribute(key);
	}

	/**
	 * 删除Session值
	 * 
	 * @param request
	 * @param key
	 */
	public static void removeAttr(HttpServletRequest request, String key) {
		request.getSession(true).removeAttribute(key);
	}

	/**
	 * 设置session用户名
	 * @param request
	 * @param name
	 */
	public static void setSessionUserName(HttpServletRequest request, String name) {
		logger.debug("设置session用户名"+name);
		request.getSession(true).setAttribute(SessionUtils.SESSION_USER_NAME, name);
	}

	/**
	 * 查询session中的用户名
	 * @param request
	 * 
	 */
	public static Object getSessionUserName(HttpServletRequest request) {
		return request.getSession(true).getAttribute(SessionUtils.SESSION_USER_NAME);
	}
	/**
	 * 删除session中的用户名
	 * @param request
	 * 
	 * */
	public static void removeSessionUserName(HttpServletRequest request) {
		request.getSession(true).removeAttribute(SessionUtils.SESSION_USER_NAME);
	}
	
	/**
	 * 设置session用户名
	 * @param request
	 * @param name
	 */
	public static void setSessionUserNumber(HttpServletRequest request, String number) {
		request.getSession(true).setAttribute(SessionUtils.SESSION_USER_NUMBER, number);
	}

	/**
	 * 查询session中的用户名
	 * @param request
	 * 
	 */
	public static Object getSessionUserNumber(HttpServletRequest request) {
		return request.getSession(true).getAttribute(SessionUtils.SESSION_USER_NUMBER);
	}
	/**
	 * 删除session中的用户名
	 * @param request
	 * 
	 * */
	public static void removeSessionUserNumber(HttpServletRequest request) {
		request.getSession(true).removeAttribute(SessionUtils.SESSION_USER_NUMBER);
	}
	
	/**
	 * 设置session中的柜员所属机构号
	 * 
	 **/
	public static void setSessionUserOri(HttpServletRequest request,String ori)
	{
		request.getSession(true).setAttribute(SessionUtils.SESSION_USER_ORI, ori);

	}
	
	
	/**
	 * 查询session中的柜员所属机构
	 * 
	 * */
	public static Object getSessionUserOri(HttpServletRequest request)
	{
		return  request.getSession(true).getAttribute(SessionUtils.SESSION_USER_ORI);
	}
	
	/**
	 * 设置session中的工作日期
	 * 
	 * */
	public static void setSessionWorkdate(HttpServletRequest request, String workdate){
		  request.getSession(true).setAttribute(SESSION_WORK_DATE, workdate);
	}
	
	/**
	 * 查询session中的工作日期
	 * 
	 * **/
	public static Object getSessionWorkdate(HttpServletRequest request){
		return request.getSession().getAttribute(SESSION_WORK_DATE);
	}
	
	
	/**
	 * 移除seesion中的机构号
	 * 
	 * **/
	public  static void removeSessoionUserOri(HttpServletRequest request){
		request.getSession().removeAttribute(SESSION_USER_ORI);
	}
	
	
	/**
	 * 移除session中的机构工作日期
	 * **/
	public static void  removeSessionWokedate(HttpServletRequest request)
	{
		request.getSession().removeAttribute(SESSION_WORK_DATE);
	}
	
	/**
	 * 设置session柜员ID
	 * 
	 * */
	public static void setSessionTellerid(HttpServletRequest request, String tellerId){
		request.getSession().setAttribute(SESSION_USER_ID, tellerId);
	}
	
	/**
	 * 
	 * 查询 sesion 柜员ID
	 */
	public static Object getSessionTellerid(HttpServletRequest request){
		return  request.getSession().getAttribute(SESSION_USER_ID);
	}
	
	/**
	 * 移除session 柜员ID
	 * */
	public static void removeSessionTellerid(HttpServletRequest request){
		request.getSession().removeAttribute(SESSION_USER_ID);
	}
}
